﻿/**
 * 房间中玩家數據類
 * @author LuoDong
 * @email luo4521@online.net.tw
 */
package com.addcn.texas.data
{			
	
	public class  UserPool 
	{		
		private static var _instance : UserPool;		
		private var _user_data : Object;		
		
		function UserPool( ) : void {
			if (_instance != null) {
				trace("[UserPool] 为单例类!");
			}else{
				_user_data = {};
			}
		}		
		
		override public function initialize(r_data:Object):void 
		{
			super.initialize(r_data);
			this._chip = parseInt(r_data["chip"]);			
			this._sit = parseInt(r_data["sit"]);			
		}
		
		public function add(r_user : User) : void
		{
			var _uid : int = r_user.id;
			_user_data[_uid] = r_user;			
		}
		
		public function remove(r_m : * ) : void
		{
			var _uid : int;
			if (r_m is User) {
				_uid = r_m.id;				
			}else {
				_uid = int(r_m);
			}
			this._user_data[_uid] = null;
			delete this._user_data[_uid] 
		}
		
		public function getUser(r_uid : int) : User
		{
			var _user : User = this._user_data[r_uid];
			return _user;.
			
		}
		
		public static function getInstance() : UserPool
		{
			if (UserPool._instance == null) {
				UserPool._instance = new UserPool();
			}
			return UserPool._instance;
		}
			
		/**
		 * 銷毀數據
		 */
		override  public function destroy() : void
		{				
			for (var k in _user_data) {
				delete _user_data[k];
			}			
		}
		
	}
	
}
